home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-02 | 9.3 KB | 341 lines | [TEXT/CWIE] |
- /*
- Written by Norman Basham, Feb. 1994
- With very minor changes by Hiep Dam, Sept. 1994
- */
-
- // ------------------------------------------------------------------------
- #include <Script.h> // GetMBarHeight ()
- // #include <QDOffscreen.h>
- #include "Monitors.h"
-
- // UTILITY STUFF
- short abs (short i);
-
- // ------------------------------------------------------------------------
- void Place (WindowPtr wp, short place)
- {
- short top;
- short left;
-
- switch (place)
- {
- case kOnBigDevice:
- GetCenteredWindowTopLeft (wp, (**GetBigDevice ()).gdRect, &top, &left);
- break;
-
- case kOnDeepDevice:
- top = GetDeepDeviceGRect().top + wp->portRect.top + GetDragBarHeight (wp);
- if (GetMainDevice () == GetMaxDevice (&(**GetGrayRgn ()).rgnBBox))
- top += GetDragBarHeight (wp);
- left = GetDeepDeviceGRect().left + wp->portRect.left;
- break;
-
- case kCenterOnDeepDevice:
- GetCenteredWindowTopLeft (wp, GetDeepDeviceGRect(), &top, &left);
- break;
-
- case kOnMainDevice:
- top = (**GetMainDevice ()).gdRect.top + wp->portRect.top + GetDragBarHeight (wp) + GetDragBarHeight (wp);
- left = (**GetMainDevice ()).gdRect.left + wp->portRect.left;
- break;
-
- case kCenterOnMainDevice:
- GetCenteredWindowTopLeft (wp, (**GetMainDevice ()).gdRect, &top, &left);
- break;
-
- }
- Move (wp, top, left);
- ShowWindow (wp);
- }
-
- // ------------------------------------------------------------------------
- void GetCenteredWindowTopLeft (WindowPtr wp, const Rect screenRect, short *top, short *left)
- {
- Rect rectToCenter = wp->portRect;
- Point p;
- short centerOnRectH;
- short centerOnRectV;
- short rectToCenterH;
- short rectToCenterV;
-
- centerOnRectH = abs (screenRect.right - screenRect.left);
- centerOnRectV = abs (screenRect.bottom - screenRect.top);
- rectToCenterH = abs (rectToCenter.right - rectToCenter.left);
- rectToCenterV = abs (rectToCenter.bottom - rectToCenter.top);
-
- *left = screenRect.left + (centerOnRectH - rectToCenterH)/2;
- *top = screenRect.top + (centerOnRectV - rectToCenterV)/2;
- p.h = *left;
- p.v = *top;
- if (PtInRect (p, &(**GetMainDevice ()).gdRect))
- *top += GetDragBarHeight (wp)/2;
-
- *top += GetDragBarHeight (wp)/2;
- }
-
-
- // ------------------------------------------------------------------------
- void Move (WindowPtr wp, short top, short left)
- {
- Boolean bringToFront = false;
-
- MoveWindow (wp, left, top, bringToFront);
- }
-
- // ------------------------------------------------------------------------
- short GetDragBarHeight (WindowPtr wp)
- {
- WindowPeek wpPeek = (WindowPeek) wp;
- short height = 19;
-
- if (wpPeek->visible) // otherwise these values can be bogus
- height = (**wpPeek->contRgn).rgnBBox.top - (**wpPeek->strucRgn).rgnBBox.top;
-
- return height;
- }
-
-
- // ------------------------------------------------------------------------
- // DEVICE STUFF
- // Norman Basham, February 1994
- // ------------------------------------------------------------------------
-
-
- // CODE
- // ------------------------------------------------------------------------
-
-
- // ------------------------------------------------------------------------
- // Get the rect in global coords of passed device
- // ------------------------------------------------------------------------
- Rect GetDeviceGRect (GDHandle gdh)
- {
- return (**GetMaxDevice (&(**gdh).gdRect)).gdRect;
- }
-
- // ------------------------------------------------------------------------
- // Get the monitor with the most depth and return its rect in global coords
- // ------------------------------------------------------------------------
- Rect GetDeepDeviceGRect ()
- {
- GDHandle gdh = GetMaxDevice (&(**GetGrayRgn ()).rgnBBox);
-
- return (**GetMaxDevice (&(**gdh).gdRect)).gdRect;
- }
-
- // ---------------------------------------------------------------------------
- // Get deepest device
- // ---------------------------------------------------------------------------
-
- GDHandle GetDeepestDevice() {
- GDHandle gdh;
- gdh = GetMaxDevice (&(**GetGrayRgn ()).rgnBBox);
- return(gdh);
- } // END GetDeepestDevice
-
- // ------------------------------------------------------------------------
- // Given a device, return wether it is a monitor and wether it's active
- // ------------------------------------------------------------------------
- Boolean IsMainDevice
- (
- GDHandle theDevice
- )
- {
- return (theDevice == GetMainDevice ());
- }
-
- // ------------------------------------------------------------------------
- // Given a device, return wether it is a monitor and wether it's active
- // ------------------------------------------------------------------------
- Boolean IsActiveScreenDevice
- (
- GDHandle theDevice
- )
- {
- return (
- (TestDeviceAttribute (theDevice, screenDevice)) &&
- (TestDeviceAttribute (theDevice, screenActive))
- );
- }
-
- // ------------------------------------------------------------------------
- // Given a device, return its depth
- // ------------------------------------------------------------------------
- short GetDeviceDepth (GDHandle gdh)
- {
- return (**(**gdh).gdPMap).pixelSize;
- }
-
- // ------------------------------------------------------------------------
- // Given a depth, GetDeviceWithThisDepth gets the first device with that
- // depth, we check main device first.
- // ------------------------------------------------------------------------
- GDHandle GetDeviceWithThisDepth (short depth)
- {
- GDHandle aGDevice;
-
- aGDevice = GetDeviceList();
- while (aGDevice != nil)
- {
- if (depth == GetDeviceDepth(aGDevice))
- return aGDevice;
-
- aGDevice = GetNextDevice (aGDevice);
- }
-
- return nil;
- }
-
- // ------------------------------------------------------------------------
- // Get the biggest monitor
- // ------------------------------------------------------------------------
- GDHandle GetBigDevice (void)
- {
- GDHandle aGDevice = nil;
- GDHandle bigGDevice = nil;
- long biggestArea = 0L;
-
- aGDevice = GetDeviceList ();
- while (aGDevice != nil)
- {
- if (IsActiveScreenDevice (aGDevice))
- {
- if (GetRectArea ((**aGDevice).gdRect) > biggestArea)
- {
- bigGDevice = aGDevice;
- biggestArea = GetRectArea ((**aGDevice).gdRect);
- }
-
- aGDevice = GetNextDevice (aGDevice);
- }
- }
-
- return bigGDevice;
- }
-
- // ------------------------------------------------------------------------
- // Given rect r, which device does it overlap most. An example of its use
- // would be passing in (**wp->visRgn).rgnBBox to find out which device a
- // window is overlapping the most, as in the case of zooming a window.
- // ------------------------------------------------------------------------
- GDHandle GetDominantDevice (Rect *r)
- {
- GDHandle aGDevice;
- GDHandle bigGDevice;
- Rect screenRect;
- Rect sectRect;
- long area;
- long biggestArea = 0L;
-
- aGDevice = GetDeviceList (); // start at begining of device list
- while (aGDevice != nil) // loop if device exists
- {
- if (IsActiveScreenDevice (aGDevice)) // if device is a monitor and active
- {
- screenRect = (**aGDevice).gdRect; // get the devices global rect
- SectRect (&screenRect, r, §Rect); // get overlapping rect of device and r
-
- area = GetRectArea (sectRect); // changed 3/21/94
- if (area > biggestArea) // if overlapping rect has the biggest area
- {
- bigGDevice = aGDevice; // set big device to current device
- biggestArea = area; // set big area to current area
- }
-
- aGDevice = GetNextDevice (aGDevice); // check next device in list
- }
- }
-
- return bigGDevice; // return device containing biggest portion of r
- }
-
- // ------------------------------------------------------------------------
- // RECT STUFF
- // Norman Basham, February 1994
- // ------------------------------------------------------------------------
-
- void CenterRect
- (
- const Rect centerOnRect,
- Rect *rectToCenter
- )
- {
- short centerOnRectH;
- short centerOnRectV;
- short rectToCenterH;
- short rectToCenterV;
-
- if ( GetRectArea (*rectToCenter) < GetRectArea (centerOnRect) )
- {
- centerOnRectH = abs (centerOnRect.right - centerOnRect.left);
- centerOnRectV = abs (centerOnRect.bottom - centerOnRect.top);
- rectToCenterH = abs (rectToCenter->right - rectToCenter->left);
- rectToCenterV = abs (rectToCenter->bottom - rectToCenter->top);
-
- SetRect (rectToCenter,
- centerOnRect.left + (centerOnRectH - rectToCenterH)/2,
- centerOnRect.top + (centerOnRectV - rectToCenterV)/2,
- centerOnRect.left + (centerOnRectH - rectToCenterH)/2 + rectToCenterH,
- centerOnRect.top + (centerOnRectV - rectToCenterV)/2 + rectToCenterV
- );
- }
- }
-
- // ------------------------------------------------------------------------
-
- void GlobalToLocalRect
- (
- Rect *r
- )
- {
- GlobalToLocal (&topLeft(*r)); // convert first word of r
- GlobalToLocal (&botRight(*r)); // convert second word of r
- }
-
- // ------------------------------------------------------------------------
-
- long GetRectArea
- (
- Rect r
- )
- {
- Rect temp = r;
-
- OffsetRect (&temp, -temp.left, -temp.top); // rids us of neg values
- return (long) temp.right * temp.bottom; // return width x heigth
- }
-
- // ------------------------------------------------------------------------
-
- void ZeroTopLeft
- (
- Rect *r
- )
- {
- OffsetRect (r, -r->left, -r->top);
- }
-
- // ------------------------------------------------------------------------
-
- void SetTopLeft
- (
- Rect *r,
- short top,
- short left
- )
- {
- ZeroTopLeft (r);
- OffsetRect (r, left, top);
- }
-
- // ------------------------------------------------------------------------
-
- short abs (short i)
- {
- if (i < 0)
- return -i;
-
- return i;
- }
-
-